package com.itany.corejava.day16;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Set;

public class ChatRoomServer {

    private ServerSocket ss;
    private Set<Socket> allSockets;

    public ChatRoomServer() {
        try {
            //启动服务
            ss=new ServerSocket(8888);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    public void startService(){
        while(true){
            Socket s=null;
            try{
                s=ss.accept();
                //将s放入allSockets中

                //启动线程

            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }

    private class ChatRoomServerThread extends Thread {

        private Socket s;

        public ChatRoomServerThread(Socket s) {
            this.s = s;
        }

        @Override
        public void run() {
            //不停的从s中获得聊天消息
                //如果是退出消息
                    //关闭socket
                    //将当前socket从allSockets中删除
                    //方法结束，当前线程结束

                //将消息发送给所有客户端，聊天消息上加上服务器时间
        }
    }


    public static void main(String[] args) {
        new ChatRoomServer().startService();
    }
}
